//
//  KZExamProgressView.m
//  lg_zhinengbeikao_english
//
//  Created by 朱凯 on 2019/1/8.
//  Copyright © 2019 zhukai. All rights reserved.
//

#import "KZExamProgressView.h"

@implementation KZExamProgressView
{
    UIImageView *_progressBgView;
    UIImageView *_progressView;
    CAShapeLayer *_progressLayer;
    
    UILabel *_titleLabel;
}

- (instancetype)init {
    
    if (self = [super init]) {
        
        _totalIndex = 0;
        _index = 0;
        [self setupUI];
    }
    return self;
}

- (void)setupUI {

    _progressBgView = [UIImageView new];
    _progressBgView.image = [UIImage imageNamed:@"kz-进度底纹条"];
    [self addSubview:_progressBgView];
    [_progressBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.equalTo(self);
        make.height.mas_equalTo(5);
    }];
    
    _progressView = [UIImageView new];
    _progressView.image = [UIImage imageNamed:@"kz-进度完整条"];
    [self addSubview:_progressView];
    [_progressView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
    
    _progressLayer = [CAShapeLayer layer];
    _progressLayer.lineWidth = 5;
    _progressLayer.strokeStart = 0;
    _progressLayer.strokeColor = UIColor.whiteColor.CGColor;
    _progressLayer.fillColor = UIColor.clearColor.CGColor;
    _progressView.layer.mask = _progressLayer;
    UIBezierPath *path = [UIBezierPath bezierPath];
    [path moveToPoint:CGPointMake(0, 2.5)];
    [path addLineToPoint:CGPointMake(SCREEN_WIDTH, 2.5)];
    _progressLayer.path = path.CGPath;
    
    _titleLabel = [[UILabel alloc] init];
    _titleLabel.adjustsFontSizeToFitWidth = true;
    _titleLabel.numberOfLines = 1;
    _titleLabel.text = @"一、听短对话(共5段对话，每段对话1个小题)";
    _titleLabel.font = FONT(14);
    _titleLabel.textAlignment = NSTextAlignmentLeft;
    _titleLabel.textColor = [UIColor blackColor];
    [self addSubview:_titleLabel];
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(W(10));
        make.right.mas_equalTo(W(-10));
        make.bottom.mas_equalTo(-5);
    }];
    
    UIView *line = [UIView new];
    line.backgroundColor = kLineColor;
    [self addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(self);
        make.height.equalTo(@1);
    }];
}
- (void)setIndex:(NSInteger)index {
    
    _index = index;
    
    _progressLayer.strokeEnd = _index * 1.0 / _totalIndex;
}

@end
